/*     */ package com.feeyin.radar.sys.controller;
/*     */ 
/*     */ import com.feeyin.radar.commons.StringUtils;
/*     */ import com.feeyin.radar.sys.model.Department;
/*     */ import com.feeyin.radar.sys.service.DepartmentService;
/*     */ import com.feeyin.radar.sys.service.UserService;
/*     */ import java.util.ArrayList;
/*     */ import java.util.HashMap;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import javax.servlet.http.HttpServletRequest;
/*     */ import javax.servlet.http.HttpServletResponse;
/*     */ import org.springframework.web.servlet.ModelAndView;
/*     */ import org.springframework.web.servlet.mvc.multiaction.MultiActionController;
/*     */ import org.springframework.web.servlet.view.RedirectView;
/*     */ 
/*     */ public class DepartmentController extends MultiActionController
/*     */ {
/*     */   private DepartmentService departmentService;
/*     */   private UserService userService;
/*     */   private String deptManage;
/*     */   private String addDepartment;
/*     */   private String updateDepartment;
/*     */ 
/*     */   public DepartmentService getDepartmentService()
/*     */   {
/*  35 */     return this.departmentService;
/*     */   }
/*     */ 
/*     */   public void setDepartmentService(DepartmentService departmentService) {
/*  39 */     this.departmentService = departmentService;
/*     */   }
/*     */ 
/*     */   public UserService getUserService() {
/*  43 */     return this.userService;
/*     */   }
/*     */ 
/*     */   public void setUserService(UserService userService) {
/*  47 */     this.userService = userService;
/*     */   }
/*     */ 
/*     */   public String getDeptManage() {
/*  51 */     return this.deptManage;
/*     */   }
/*     */ 
/*     */   public void setDeptManage(String deptManage) {
/*  55 */     this.deptManage = deptManage;
/*     */   }
/*     */ 
/*     */   public String getAddDepartment() {
/*  59 */     return this.addDepartment;
/*     */   }
/*     */ 
/*     */   public void setAddDepartment(String addDepartment) {
/*  63 */     this.addDepartment = addDepartment;
/*     */   }
/*     */ 
/*     */   public String getUpdateDepartment() {
/*  67 */     return this.updateDepartment;
/*     */   }
/*     */ 
/*     */   public void setUpdateDepartment(String updateDepartment) {
/*  71 */     this.updateDepartment = updateDepartment;
/*     */   }
/*     */ 
/*     */   public ModelAndView display(HttpServletRequest request, HttpServletResponse response)
/*     */   {
/*  76 */     Map map = new HashMap();
/*  77 */     map.put("departments", this.departmentService.getDepartments());
/*     */ 
/*  79 */     return new ModelAndView(getDeptManage(), map);
/*     */   }
/*     */ 
/*     */   public ModelAndView preAddDepartment(HttpServletRequest request, HttpServletResponse response)
/*     */   {
/*  84 */     Map map = new HashMap();
/*  85 */     map.put("result", request.getParameter("result"));
/*  86 */     map.put("repeat", request.getAttribute("repeat"));
/*     */ 
/*  88 */     map.put("deptCode", this.departmentService.getDepartmentCode());
/*  89 */     map.put("departments", this.departmentService.getDepartments());
/*     */ 
/*  91 */     return new ModelAndView(getAddDepartment(), map);
/*     */   }
/*     */ 
/*     */   public ModelAndView addDepartment(HttpServletRequest request, HttpServletResponse response, Department department)
/*     */   {
/*  96 */     boolean result = false;
/*  97 */     int success = 0;
/*     */ 
/*  99 */     if (department != null) {
/* 100 */       if (this.departmentService.getDepartmentByDeptName(department.getDeptName()) != null) {
/* 101 */         request.setAttribute("repeat", "1");
/* 102 */         request.setAttribute("department", department);
/* 103 */         return preAddDepartment(request, response);
/*     */       }
/*     */ 
/* 106 */       result = this.departmentService.insertDepartment(department);
/* 107 */       if (result) success = 1;
/*     */     }
/* 109 */     return new ModelAndView(new RedirectView("./department.do?action=preAddDepartment&result=" + success));
/*     */   }
/*     */ 
/*     */   public ModelAndView preUpdateDepartment(HttpServletRequest request, HttpServletResponse response)
/*     */   {
/* 114 */     Map map = new HashMap();
/* 115 */     map.put("result", request.getParameter("result"));
/* 116 */     map.put("repeat", request.getAttribute("repeat"));
/*     */ 
/* 118 */     map.put("deleteS", request.getParameter("deleteS"));
/* 119 */     map.put("deleteFail", request.getAttribute("deleteFail"));
/*     */ 
/* 121 */     map.put("departments", this.departmentService.getDepartments());
/*     */ 
/* 123 */     String id = request.getParameter("id");
/* 124 */     Department department = new Department();
/* 125 */     if ((id != null) && (!"".equals(id))) {
/* 126 */       department = this.departmentService.getDepartment(Integer.valueOf(Integer.parseInt(id)));
/*     */     }
/* 128 */     map.put("department", department);
/* 129 */     return new ModelAndView(getUpdateDepartment(), map);
/*     */   }
/*     */ 
/*     */   public ModelAndView updateDepartment(HttpServletRequest request, HttpServletResponse response, Department department)
/*     */   {
/* 134 */     Map map = new HashMap();
/*     */ 
/* 136 */     boolean result = false;
/* 137 */     int success = 0;
/* 138 */     if (department != null) {
/* 139 */       if (this.departmentService.isRepeatUpdateDepartment(department)) {
/* 140 */         request.setAttribute("repeat", "1");
/* 141 */         request.setAttribute("department", department);
/* 142 */         return preUpdateDepartment(request, response);
/*     */       }
/*     */ 
/* 145 */       result = this.departmentService.updateDepartment(department);
/* 146 */       if (result) success = 1;
/*     */     }
/*     */ 
/* 149 */     return new ModelAndView(new RedirectView("./department.do?action=preUpdateDepartment&id=" + department.getId() + "&result=" + success));
/*     */   }
/*     */ 
/*     */   public ModelAndView deleteDepartment(HttpServletRequest request, HttpServletResponse response, Department department)
/*     */   {
/* 154 */     boolean result = false;
/* 155 */     int success = 0;
/*     */ 
/* 157 */     String id = request.getParameter("id");
/* 158 */     if (!StringUtils.isEmpty(id)) {
/* 159 */       List list = new ArrayList();
/* 160 */       list = this.departmentService.getDepartmentByParentId(department.getId());
/* 161 */       if ((list != null) && (list.size() > 0)) {
/* 162 */         request.setAttribute("deleteFail", "1");
/* 163 */         request.setAttribute("department", department);
/* 164 */         return preUpdateDepartment(request, response);
/*     */       }
/*     */ 
/* 170 */       if (this.departmentService.isUseDepartment(department.getId())) {
/* 171 */         request.setAttribute("deleteFail", "2");
/* 172 */         request.setAttribute("department", department);
/* 173 */         return preUpdateDepartment(request, response);
/*     */       }
/*     */ 
/* 176 */       result = this.departmentService.deleteDepartment(Integer.valueOf(Integer.parseInt(id)));
/* 177 */       if (result) success = 1;
/*     */     }
/* 179 */     return new ModelAndView(new RedirectView("./department.do?action=preUpdateDepartment&id=" + department.getId() + "&deleteS=" + success));
/*     */   }
/*     */ }

/* Location:           C:\Users\e547415\MyProject\rone\WEB-INF\classes\
 * Qualified Name:     com.feeyin.radar.sys.controller.DepartmentController
 * JD-Core Version:    0.6.0
 */